<html>
<head><meta charset="utf-8"><title>html/format.rs rewrite? · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/html.2Fformat.2Ers.20rewrite.3F.html">html/format.rs rewrite?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227320325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/html/format.rs%20rewrite%3F/near/227320325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/html.2Fformat.2Ers.20rewrite.3F.html#227320325">(Feb 22 2021 at 19:09)</a>:</h4>
<p>I'm currently slowly but steadily converting more types into the hir equivalents and I just hit a huge bottleneck: I need to provide <code>tcx</code> into <code>html/format.rs</code> functions, which is a disaster from a lifetime perspective. Should we maybe try to simplify it? The <code>display_fn</code> call doesn't need to be called everywhere I think for example, instead I'm thinking about providing another method alongisde <code>print</code> which will receive the <code>fmt::Formatter</code> parameter. What do you think?</p>
<p>PS: the PR I'm working on is: <a href="https://github.com/rust-lang/rust/compare/master...GuillaumeGomez:rustdoc-const-ty?expand=1">https://github.com/rust-lang/rust/compare/master...GuillaumeGomez:rustdoc-const-ty?expand=1</a></p>
<p>The goal was to reduce the size of the <code>struct Const</code> and do some conversion on demand instead of ahead of time like now.</p>



<a name="227325205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/html/format.rs%20rewrite%3F/near/227325205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/html.2Fformat.2Ers.20rewrite.3F.html#227325205">(Feb 22 2021 at 19:41)</a>:</h4>
<p>Regarding the lifetimes, since <code>TyCtxt</code> is invariant in its lifetime param, you should be using a free distinct lifetime parameter for it, one so that <code>'tcx : 'a</code>, where <code>'a</code> is the lifetime for the other params (otherwise I imagine you will not be able to call the functions defined in <code>html/format.rs</code>).<br>
Then, on the <code>impl</code> return type, you write <code>-&gt; impl Display + 'a + Captures&lt;'tcx&gt;</code> (<em>c.f.</em> <a href="https://doc.rust-lang.org/stable/nightly-rustc/rustc_data_structures/captures/trait.Captures.html">https://doc.rust-lang.org/stable/nightly-rustc/rustc_data_structures/captures/trait.Captures.html</a>)<br>
(The reason for needing that is that <code>-&gt; impl …</code> desugaring is currently a bit dumb, and only introduces parameters (for the existential type) for each parameter <em>used in that <code>impl …</code></em> (instead of defining an existential type parameter <em>for each parameter in scope</em>).</p>
<p>That is, instead of doing:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">//               generic parameters that were in scope when you wrote `-&gt; impl …`</span>
<span class="c1">//               vv  vvvv</span>
<span class="k">type</span> <span class="nc">ImplDisplay</span><span class="o">&lt;'</span><span class="na">a</span><span class="p">,</span><span class="w"> </span><span class="o">'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="n">Display</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">'</span><span class="na">a</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>so that the <code>'tcx</code>-invariantly-infected closure can match this definition,<br>
currently, if you don't write that <code>Captures&lt;'tcx&gt;</code> hack, it does:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">type</span> <span class="nc">ImplDisplay</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="n">Display</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">'</span><span class="na">a</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="227328310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/html/format.rs%20rewrite%3F/near/227328310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/html.2Fformat.2Ers.20rewrite.3F.html#227328310">(Feb 22 2021 at 20:00)</a>:</h4>
<p>It's worth a try, thanks for the suggestion!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>